//
//  LMNewFeatureViewController.m
//  李明微博
//
//  Created by 张青花 on 15/12/6.
//  Copyright (c) 2015年 李明. All rights reserved.
//

#import "LMNewFeatureViewController.h"
#import "LMNewFeatureCell.h"
@interface LMNewFeatureViewController ()


@property(nonatomic,weak)UIPageControl *pageControl;

@end

@implementation LMNewFeatureViewController

static NSString * const reuseIdentifier = @"Cell";


- (instancetype) init
{
    
    UICollectionViewFlowLayout  *layout = [[UICollectionViewFlowLayout alloc] init];
    
    
    layout.itemSize = [UIScreen mainScreen].bounds.size;
    
    layout.minimumLineSpacing = 0;
    
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    return [super initWithCollectionViewLayout:layout];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.collectionView registerClass:[LMNewFeatureCell class] forCellWithReuseIdentifier:reuseIdentifier];
    
    self.collectionView.pagingEnabled = YES;
    
    self.collectionView.bounces =NO;
    
    self.collectionView.showsHorizontalScrollIndicator = NO;
    
    [self setPageControl];
    
    
}


- (void)setPageControl
{
    UIPageControl *pageControl = [[UIPageControl alloc] init];
    
    pageControl.numberOfPages = 4;
    
    pageControl.pageIndicatorTintColor = [UIColor blackColor];
    
    pageControl.currentPageIndicatorTintColor = [UIColor redColor];
    
    pageControl.center = CGPointMake(self.view.width*0.5, self.view.height);
    _pageControl = pageControl;
    [self.view addSubview:_pageControl];
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    int page = scrollView.contentOffset.x/scrollView.bounds.size.width+0.5;
    
    _pageControl.currentPage = page;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 4;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    LMNewFeatureCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    
    NSString *imageName = [NSString stringWithFormat:@"new_feature_%d",indexPath.row + 1];
    
    
    UIImage *image = [UIImage imageNamed:imageName];
    cell.image = image;
    
    [cell setIndexPath:indexPath count:4];
    return cell;
}


@end
